package com.zy.dubbo.demo.user.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.dubbo.demo.component.I18nUtil;
import com.zy.dubbo.demo.constants.ResponseMsg;
import com.zy.dubbo.demo.user.model.User;
import com.zy.dubbo.demo.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * UserController
 *
 * @author Robbin Zhao
 * @since 2020-12-10
 */
@RestController
@RequestMapping("user")
@Slf4j
public class UserController {

    @DubboReference
    private UserService userService;

    @Resource
    private I18nUtil i18nUtil;

    @RequestMapping("getUserInfo")
    public User getUserInfo(Long id) {
        return userService.getUserById(id);
    }

    @RequestMapping("getByName")
    public List<User> getByName(String name) {
        return userService.getUserByName(name);
    }

    @RequestMapping("queryUserList")
    public Page<User> queryUserList(String name,int curPage,int pageSize) {
        return userService.queryUserList(new Page<>(curPage,pageSize), name);
    }

    @RequestMapping("success")
    public String success() {
        return i18nUtil.getI18nMsg(ResponseMsg.SUCCESS);
    }
}
